package com.ykqx.weather.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ykqx.weather.dao.TemperatureHistoricDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/6/12 0012
 */
@Controller
@RequestMapping(value="/yk")
public class TemperatureHistoricController {

    Gson gson = new GsonBuilder().create();

    @Autowired
    TemperatureHistoricDao temperatureHistoricDao;

    //headers={"Accept=text/xml,application/json"}添加头部信息该方法只处理头部信息为text/xml,application/json的请求
    @RequestMapping("/test")
    @ResponseBody
    public String test(){
        return "test success";
    }

    @RequestMapping("/getAllHistoricHigh")
    @ResponseBody
    public String getAllHistoricHigh(){
        try {
            List result = temperatureHistoricDao.getAllHistoricHigh();
            String resultStr = gson.toJson(result);
            return resultStr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getAllHistoricLow")
    @ResponseBody
    public String getAllHistoricLow(){
        try {
            List result = temperatureHistoricDao.getAllHistoricLow();
            String resultStr = gson.toJson(result);
            return resultStr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping(value="/getAllHistoricAverage")
    @ResponseBody
    public String getAllHistoricAverage(){
        try {
            List result = temperatureHistoricDao.getAllHistoricAverage();
            String resultStr = gson.toJson(result);
            return resultStr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getAllHistoricAverageHigh")
    @ResponseBody
    public String getAllHistoricAverageHigh(){
        try {
            List result = temperatureHistoricDao.getAllHistoricAverageHigh();
            String resultStr = gson.toJson(result);
            return resultStr;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
